namespace _2.策略模式;

public partial class Form1 : Form
{
    double total = 0.0d;//总价

    public Form1()
    {
        InitializeComponent();
    }

    private void btnOk_Click(object sender, EventArgs e)
    {
        //获取下拉框中的折扣方案字符串，传给CashContext构造方法创建对应折扣方案对象。
        CashContext csuper = new CashContext(cbxType.SelectedItem.ToString());
        double totalPrices = 0.0d;
        //传入原价，获得现价
        totalPrices = csuper.GetResult(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text));
        //获取所有商品总价
        total = total + totalPrices;
        lbxList.Items.Add($"单价：{txtPrice.Text} 数量：{txtNum.Text} {cbxType.SelectedItem} 合计：{totalPrices:0.00}");
        lblResult.Text = total.ToString("0.00");
    }

    /// <summary>
    /// 清空
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btnReset_Click(object sender, EventArgs e)
    {
        txtPrice.Text = null;
        txtNum.Text = null;
        cbxType.SelectedIndex = 0;
        lbxList.Items.Clear();
        lblResult.Text = "0.00";
    }
}